<!--
 * @Author: MrLee
 * @Date: 2024-08-24 08:55:14
 * @LastEditors: MrLee
 * @LastEditTime: 2024-09-12 17:01:01
 * @Description: 请填写简介
-->
<template>
    <custom-navbar title="发布职位" :autoBack="true" leftIconColor="#303133" />
    <up-gap height="30rpx" />
  <!-- <search-bar :icoFlag="true"  classf="px-24rpx" classc="px-24rpx py-24rpx bg-#fff rounded-20rpx"  /> -->
  <view class="flex item-center just-between px-24rpx py-24rpx bg-#fff rounded-20rpx">
    <up-image width="66rpx" height="66rpx" shape="circle" />
    <view class="rounded-34rpx bg-#f6f6f6 flex flex-1 text-[#1d2129] items-center ml-24rpx pl-24rpx py-16rpx">北京科技有限公司</view>
  </view>
  <up-gap height="44rpx" />
  <view class="px-24rpx">
    <infocard
      :user-info-list="moreList"
      @actionTmp="oneAction"
      className="text-[#1d2129]"
    />
  </view>
  <up-gap height="30rpx" />
  <view class="px-24rpx">
    <infocard
      :user-info-list="moreListSecend"
      @actionTmp="oneAction"
      className="text-[#1d2129]"
    />
  </view>
  <up-gap height="30rpx" />
  <view class="px-24rpx">
    <infocard
      :user-info-list="moreListThird"
      @actionTmp="oneAction"
      className="text-[#1d2129]"
    />
  </view>
  <up-gap height="30rpx" />
  <view class="px-24rpx">
    <infocard :user-info-list="moreListLast" className="text-[#1d2129]" />
  </view>
  <up-gap height="200rpx" />
  <up-picker
    :show="show"
    :columns="columns"
    @confirm="confirm"
    @cancel="show = false"
  ></up-picker>
  <view
    class="fixed flex bottom-0 left-0 w-100% bg-#fff px-30rpx pt-24rpx pb-safe shadow-[0px_0px_6px_0px_rgba(238,239,241,0.50)]"
  >
    <view
      class="mx-auto my-0 mt-[24rpx] h-82rpx w-[40%] rounded-[42rpx] bg-#f7f7f8 text-center text-[30rpx] text-[#1d2129] font-medium leading-[82rpx]"
    >
      删除
    </view>
    <view
      class="mx-auto my-0 mt-[24rpx] h-82rpx w-[40%] rounded-[42rpx] bg-#1f50f2 text-center text-[30rpx] text-white font-medium leading-[82rpx]"
      @click="onClickSubmit"
    >
      发布
    </view>
  </view>
</template>
    <script setup lang="ts">
import infocard from "@/pages/components/infocard/index.vue";
import VNavbar from "../search/components/v-navbar.vue";
import {userJobType} from '@/api/user/index'
import {HRJobAdd, hrJobAddParams} from '@/api/user/company';
import { commonMajorList } from "@/api/user/common";

const moreList = ref([
  {
    title: "职位类别",
    value: "请选择",
    label: '请选择',
    rigthIco: true,
    valueType: "select",
    selectOptions: []
  },
  {
    title: "职位名称",
    value: '请选择',
    valueType: "input",
  },
  {
    title: "",
    value: undefined,
    valueType: "selects",
    selectInfo: [
      {
        label: "职位性质",
        value: "请选择",
        options: [],
      },
      {
        label: "学历要求",
        value: "请选择",
        options: [],
      },
      {
        label: "招聘人数",
        value: "",
        type: 'input',
        options: [],
      },
    ],
  },
  {
    title: "专业要求",
    value: "请选择",
    label: '请选择',
    rigthIco: true,
    valueType: "selectMultiple",
    selectOptions: [],
  },
]);
const moreListSecend = reactive([
  {
    title: "薪资范围",
    label: '请选择',
    value: "请选择",
    rigthIco: true,
    valueType: "select",
    selectOptions: []
  },
  {
    title: "岗位亮点",
    value: '请选择',
    label: '请选择',
    valueType: "selectMultiple",
  },
  {
    title: "工作时间",
    value: "",
    label: '',
    valueType: "input",
  },
  {
    title: "工作省市",
    value: "请选择",
    label: '请选择',
    rigthIco: true,
    valueType: "city",
  },
  {
    title: "工作地点",
    value: "",
    valueType: "input",
  },
]);
const moreListThird = reactive([
  {
    title: "工作内容",
    titleInfo: "请详细描述该职位的工作内容",
    value: "",
    valueType: "textarea",
    placeholder: "请详细描述该职位的工作内容",
  },
  {
    title: "任职要求",
    titleInfo: "请详细描述该职位的任职要求",
    value: "",
    valueType: "textarea",
    placeholder: "请详细描述该职位的工作内容",
  },
]);
const moreListLast = reactive([
  {
    title: "简历接收邮箱",
    value: "",
    valueType: "input",
  },
]);
let columns = reactive([]);
let show = ref(false);
let activeTitle = ref('')
const oneAction = (params) => {
  if (params.options) {
    activeTitle.value = params.label
    show.value = true;
    columns = params.options;
  }
};

const confirm = (v) => {
  moreList.value[2].selectInfo.map(vi => {
    if(vi.label === activeTitle.value) {
      vi.value = v.value[0]
    }
  })
  activeTitle.value = ''
  show.value = false
};
onMounted(() => {
  let config = JSON.parse(uni.getStorageSync('config')).configCli
  moreListSecend[1].selectOptions = config.config_job_highlights$$职位亮点配置.map(v => {
    return {
      label: v.value,
      value: v.key,
      selected: false
    }
  })
  let arr = []
  config.config_job_nature$$职位性质.map(v => {
    arr.push(v.value)
  })
  moreList.value[2].selectInfo[0].options.push(arr)

  let arr2 = []
  config.config_qualification$$学历配置.map(v => {
    arr2.push(v.value)
  })
  moreList.value[2].selectInfo[1].options.push(arr2)

    config.config_salary$$薪资配置.map((item,index) => {
    if(index >= (config.config_salary$$薪资配置.length - 1)) {
      moreListSecend[0].selectOptions.push({
        label: item.value+'+',
        value: item.value
      })
    }else {
      moreListSecend[0].selectOptions.push({
        label: item.value+'-'+config.config_salary$$薪资配置[index + 1].value,
        value: item.value+'-'+config.config_salary$$薪资配置[index + 1].value
      })
    }
  })
  userJobType().then(res => {
   res.map(v => {
      if(v.level === 1) {
        moreList.value[0].selectOptions.push({
          label: v.content,
          value: v.id
        })
      }
    })
  })
  getLiangdian()
  getMajorList()
})

//获取专业列表
const getMajorList = async () => {
  let r = await commonMajorList()
  r.forEach(item => {
    moreList.value[3].selectOptions.push({
      value: item.id,
      label: item.name,
      selected: false
    })
    // let value = item.id    //专业ID(新增职位需要传递)
    // let label = item.name  //专业名称(新增职位需要选择显示用)
  })
  console.log('-----', moreList.value[3])
}

//接口-发布职位
const onClickSubmit = async () => {
  let gehighlights  = []
  let zhuanye = []
  console.log(moreListSecend[1].selectOptions)
  moreListSecend[1].selectOptions.map(v => {
    if(v.selected) {
      gehighlights.push(v.label)
    }
  })
  moreList.value[3].selectOptions.map(vi => {
    if(vi.selected) {
      zhuanye.push(vi.value)
    }
  })
  let xueli = []
  xueli.push(moreList.value[2].selectInfo[1].value)
  let params:hrJobAddParams = {
    position_id: moreList.value[0].value,   //职位类型ID   职位类型接口
    name: moreList.value[1].value, //职位名称
    nature: moreList.value[2].selectInfo[0].value,   //职位性质-全职、实习  读客户端配置接口
    qualifications: JSON.stringify(xueli),  //多选学历数组 JSOn
    recruit_num: moreList.value[2].selectInfo[2].value,   //招聘人数
    majors_content: JSON.stringify(zhuanye),  //专业ID数组
    salary_min: moreListSecend[0].value.split('-')[0],
    salary_max: moreListSecend[0].value.split('-')[1] ? moreListSecend[0].value.split('-')[1] : moreListSecend[0].value.split('-')[0],
    salary_count: moreListSecend[0].value.split('-')[0],  //薪资期望
    highlights: JSON.stringify(gehighlights),  //职位亮点
    job_time: moreListSecend[2].value,  //工作时间
    province_id: moreListSecend[3].value.split(',')[0],    //省code
    city_id: moreListSecend[3].value.split(',')[1],    //市code
    adress_detail: moreListSecend[4].value,  //详细地址
    job_content: moreListThird[0].value,  //职位描述(富文本)
    job_requirements: moreListThird[1].value,  //任职要求(富文本)
    adress_email: moreListLast[0].value,  //简历接收邮箱
  }
  if(params.position_id === '请选择') {
    await uni.showToast({
      title: '请选择职位类型',
      icon: 'none'
    })
  }
  if( params.name === '请选择') {
    await uni.showToast({
      title: '请选择职位名称',
      icon: 'none'
    })
  }
  if(params.nature === '请选择') {
    await uni.showToast({
      title: '请选择职位性质',
      icon: 'none'
    })
  }
  if(params.qualifications === '请选择') {
    await uni.showToast({
      title: '请选择学历',
      icon: 'none'
    })
  }
  if (params.recruit_num === '请选择') {
    await uni.showToast({
      title: '请输入招聘人数',
      icon: 'none'
    })
  }
  if (params.majors_content === '请选择') {
    await uni.showToast({
      title: '请选择专业',
      icon: 'none'
    })
  }
  if (params.salary_min === '') {
    await uni.showToast({
      title: '请输入薪资下限',
      icon: 'none'
    })
  }
  if (params.salary_max === '') {
    await uni.showToast({
      title: '请输入薪资上限',
      icon: 'none'
    })
  }
  if (params.highlights === '') {
    await uni.showToast({
      title: '请选择职位亮点',
      icon: 'none'
    })
  }
  if (params.job_time === '') {
    await uni.showToast({
      title: '请输入工作时间',
      icon: 'none'
    })
  }
  if (params.province_id === '') {
    await uni.showToast({
      title: '请选择工作地点',
      icon: 'none'
    })
  }
  if (params.city_id === '') {
    await uni.showToast({
      title: '请选择工作地点',
      icon: 'none'
    })
  }
  if (params.adress_detail === '') {
    await uni.showToast({
      title: '请输入详细地址',
      icon: 'none'
    })
  }
  if (params.job_content === '') {
    await uni.showToast({
      title: '请输入职位描述',
      icon: 'none'
    })
  }
  if (params.job_requirements === '') {
    await uni.showToast({
      title: '请输入任职要求',
      icon: 'none'
    })
  }
  if(params.address_email === '') {
    await uni.showToast({
      title: '请输入邮箱',
      icon: 'none'
    })
  }
  console.log('参数：：：', params)
  let r = await HRJobAdd(params)
  if (r) {
    uni.navigateBack()
  } else {
    uni.showToast({
      title: '发布职位失败',
      icon: 'none'
    })
  }
}
const getLiangdian = () => {
  let arr = []
}
</script>
